
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>编辑投票信息</title>
<link rel="stylesheet"
	href="https://fonts.googleapis.com/css?family=Roboto:400,700" />
<!-- https://fonts.google.com/specimen/Roboto -->
<link rel="stylesheet" href="../css/fontawesome.min.css" />
<!-- https://fontawesome.com/ -->
<link rel="stylesheet" href="../jquery-ui-datepicker/jquery-ui.min.css"
	type="text/css" />
<!-- http://api.jqueryui.com/datepicker/ -->
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<!-- https://getbootstrap.com/ -->
<link rel="stylesheet" href="../css/templatemo-style.css">
<!--
	Product Admin CSS Template
	https://templatemo.com/tm-524-product-admin
	-->
</head>
<script src="../js/jquery-1.7.2.js"></script>
<script type="text/javascript">
	let re2 = new RegExp("\s?" + "item_id" + "=([^;]+)(;|$)")
	var item_id=document.cookie.match(re2)[1];
	function updateVoteItem(){
		var item_title = document.getElementById("votename").value;
		var item_text = document.getElementById("votetext").value;
		
		$.ajax({
			url : "http://localhost:8080/voting-system/updateItem",
			type : "post",
			success : function(data) {
				if(data.insertItem==false){
					alert("更新失败！")
				}else{
					alert("更新成功！")
					//window.location.href='manage.html'
				}
			},
			dataType : "json",
			data:{item_id:item_id, item_title:item_title, item_text:item_text}
		});
	}
	function editVoteItem(){
		window.location.href='edit-vote.html'
	}

</script>
<body>
	<nav class="navbar navbar-expand-xl">
		<div class="container h-100">

			<button class="navbar-toggler ml-auto mr-0" type="button"
				data-toggle="collapse" data-target="#navbarSupportedContent"
				aria-controls="navbarSupportedContent" aria-expanded="false"
				aria-label="Toggle navigation">
				<i class="fas fa-bars tm-nav-icon"></i>
			</button>

			<div class="collapse navbar-collapse" id="navbarSupportedContent">
				<ul class="navbar-nav mx-auto h-100">
					<li class="nav-item"><a class="nav-link" href="result.jsp">
							<i class="fas fa-tachometer-alt"></i> 投票结果 <span class="sr-only">(current)</span>
					</a></li>
					<li class="nav-item dropdown"><a
						class="nav-link dropdown-toggle" href="update.html"> <i
							class="far fa-file-alt"></i> <span>用户管理 </span>
					</a></li>
					<li class="nav-item"><a class="nav-link active"
						href="manage.html"> <i class="fas fa-shopping-cart"></i> 投票管理
					</a></li>

					<li class="nav-item"><a class="nav-link" href="center.html">
							<i class="far fa-user"></i> 个人中心
					</a></li>

				</ul>
				<ul class="navbar-nav">
					<li class="nav-item"><a class="nav-link d-block"
						href="../login.html"> <b>退出登录</b>
					</a></li>
				</ul>
			</div>
		</div>
	</nav>
	<div class="container tm-mt-big tm-mb-big">
		<div class="row">
			<div class="col-xl-9 col-lg-10 col-md-12 col-sm-12 mx-auto">
				<div class="tm-bg-primary-dark tm-block tm-block-h-auto">
					<div class="row">
						<div class="col-12">
							<h2 class="tm-block-title d-inline-block">编辑投票信息</h2>
						</div>
					</div>
					<div class="row tm-edit-product-row">
						<div class="col-xl-6 col-lg-6 col-md-12">
							<form method="post" class="tm-edit-product-form">
								<div class="form-group mb-3">
									<label for="name">投票名 </label> <input
										id="votename" name="votename" type="text"
										class="form-control validate" />
								</div>
								<div class="form-group mb-3">
									<label for="description">描述信息</label>
									<textarea id="votetext" name="votetext" class="form-control validate tm-small" rows="5"
										required>在此处填写投票信息</textarea>
								</div>
						
						<button type="button" onclick="editVoteItem()"
							class="btn btn-primary btn-block text-uppercase mb-3">编辑投票项目</button>

						<button type="submit" onclick="updateVoteItem()"
							class="btn btn-primary btn-block text-uppercase">点我确认更新</button>

						</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>


	<script src="../js/jquery-3.3.1.min.js"></script>
	<!-- https://jquery.com/download/ -->
	<script src="../jquery-ui-datepicker/jquery-ui.min.js"></script>
	<!-- https://jqueryui.com/download/ -->
	<script src="../js/bootstrap.min.js"></script>
	<!-- https://getbootstrap.com/ -->
	<script>
		$(function() {
			$("#expire_date").datepicker({
				defaultDate : "10/22/2020"
			});
		});
	</script>
</body>
</html>
